package cc.ucanuup.config.base;

import java.io.IOException;
import java.util.UUID;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;

/**
 * 文件名： com.bozhon.filter.SessionFilter.java
 * 作者：   WenBin
 * 日期：   2017年11月25日
 * 功能说明： 过滤器，用户配置基本参数 和初始化参数
 * =========================================================
 * 修改记录：
 * 修改作者    日期      修改内容
 * =========================================================
 *  Copyright (c) 2010-2011 .All rights reserved.
 */
public class ConfigFilter implements Filter {

	@Value("${web.path}")
	private String  webPath ;

	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)throws IOException, ServletException {
		HttpServletRequest httpRequest = (HttpServletRequest) arg0;
		httpRequest.setAttribute("basePath", webPath);
		/*		httpRequest.setAttribute("startTime", DateUtil.getThisMonthFirstDay());
		httpRequest.setAttribute("endTime", DateUtil.getThisMonthLastDay());*/
		httpRequest.getSession().setAttribute("uploadCode", UUID.randomUUID().toString());
		arg2.doFilter(arg0, arg1);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {

	}
}